//
//  YygZhongViewController.m
//  ShangChengMoBan
//
//  Created by 军 on 16/8/27.
//  Copyright © 2016年 ping. All rights reserved.
//一元购中奖纪录

#import "YygZhongViewController.h"
#import "ZhongJiangTableViewCell.h"
@interface YygZhongViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation YygZhongViewController
{
    int _page;
    RWScrollView * _table;
    NSMutableArray * _arr;
}
-(void)headRefresh{
    _page = 1;
    [self jiangRequestData:1];
}
-(void)footerRefresh{
    _page ++;
    [self jiangRequestData:0];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    _page = 1;
    _table =[[RWScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-104)];
    [_table addHeaderWithTarget:self action:@selector(headRefresh)];
    [_table headerBeginRefreshing];
    [_table addFooterWithTarget:self action:@selector(footerRefresh)];
    _table.separatorStyle =  UITableViewCellSelectionStyleNone;
    _table.delegate =self;
    _table.dataSource = self;
    [_table registerClass:[ZhongJiangTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_table];
}
-(void)jiangRequestData:(int)page{
   
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[self defaultUserId] forKey:@"userId"];
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [dic setObject:@"10" forKey:@"pageSize"];
    [dic setObject:[NSString stringWithFormat:@"%d",_page] forKey:@"pageNum"];
    [dic setObject:@1 forKey:@"type"];
    [NetWorking NEWjieKouQingQiu:YYG_myYYG ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        [_table headerEndRefreshing];
        [_table footerEndRefreshing];
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                if (page == 1) {
                    _arr =  [[NSMutableArray alloc]init];
                }
               [_arr addObjectsFromArray:dic[Response]];
                [_table reloadData];
               
            }
        }
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic = _arr[indexPath.row];
    ZhongJiangTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.time.text = dic[@"createDate"];
    cell.qi.text =[NSString stringWithFormat:@"%@期", dic[@"qishuNum"]];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:dic[@"goodsMapper"][@"goodsThumb"]]];

    cell.haoMa.text = dic[@"luckNum"];
    cell.title.text = dic[@"goodsMapper"][@"goodsName"];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 110;
}


@end
